<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


<html>
<!--

POWER METAL LYRICS GENERATOR - Генератор Ипических Текстов

Redistributed under

The MIT License

Copyright (c) 2010 Vladimir Klubkov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-->

<title>POWER METAL LYRICS GENERATOR - Генератор Ипических Текстов</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="ru">

<script type="text/javascript">

// random numbers generator, min <= generated number < max !
function rand(min, max) {
    return Math.floor(Math.random() * (max - min)) + min;
}

// main dictionary
var dictionary = [
["power", "steel", "sword", "evil", "good", "princess", "king", "empire", "warrior", "dragon", "will", "flame", "metal", "madness", "war", "lord", "god", "darkness", "wind", "magic", "spell", "hate", "fate", "blood", "winner", "master"],
["die", "fight", "return", "sign", "kill",  "hail", "free", "loose"],
["is"],
 ["for", "with", "against", "to", "of", "the"]
];

// special dictionary
var chars = ["s", ",", "<br>"];
var others = ["the", "ing"];

// 1 is a noun
// 2 is a verb
// 3 is the 'is'
// 4 is a preposition or the 'the'
// 11 is the 's' ending
// 12 is the ','
// 13 is the line break
// 21 is the 'the'
// 22 is the 'ing' ending
var versePresets = [[1,  2, 11,  4, 1, 13], [21, 1,  2, 11, 13], [1,  3,  2, 22, 4,  1, 13]];

// generates verse
function createVerse(linesCount) {
    var verse = "";
    for(var i = 0; i < linesCount; i++) {
        var numPreset = rand(0, versePresets.length);
        var oldSpace = true;
        for(var j = 0; j < versePresets[numPreset].length;  j++) {
            var str = "";
            var space = true;
            switch(versePresets[numPreset][j]) {
                case 1:
                    str = dictionary[0][rand(0, dictionary[0].length)];
                    break;
                case 2:
                    str = dictionary[1][rand(0, dictionary[1].length)];
                    break;
                case 3:
                    str = dictionary[2][rand(0, dictionary[2].length)];
                    break;
                case 4:
                    str = dictionary[3][rand(0, dictionary[3].length)];
                    break;
                case 11:
                    str = chars[0];
                    space = false;
                    break;
                case 12:
                    str = chars[1];
                    space = false;
                    break;
                case 13:
                    str = chars[2];
                    oldSpace = false;
                    space = false;
                    break;
                case 21:
                    str =others[0];
                    break;
                case 22:
                    str = others[1];
                    space = false;
                    break;
                case 0:
                default:
                    space = false;
            }
            if(space) {
                if(oldSpace) {
                    if(0 != j) {
                        verse = verse+" ";
                    }
                } else {
                    oldSpace = true;
                }
            }
            if(str) {
                verse = verse+str;
            }
        }
    }
    return verse;
}

// 1 is a noun
// 2 is a verb
// 3 is the 'is'
// 4 is a preposition or the 'the'
// 11 is the 's' ending
// 12 is the ','
// 13 is the line break
// 21 is the 'the'
// 22 is the 'ing' ending
// 31 is the song name
var chorusPresets = [[31, 12, 31, 13, 2, 13, 31, 12, 31, 13,  2, 13], [31, 13, 31, 13, 31, 13, 1, 13], [2, 22, 4, 31, 13]];

// generates chorus
function createChorus(songName) {
    var chorus = "";
    var numPreset = rand(0, chorusPresets.length);
    var oldSpace = true;
    for(var i = 0; i < chorusPresets[numPreset].length; i++) {
        var str = "";
        var space = true;
        switch( chorusPresets[numPreset][i]) {
            case 1:
                str = dictionary[0][rand(0, dictionary[0].length)];
                break;
            case 2:
                str = dictionary[1][rand(0, dictionary[1].length)];
                break;
            case 3:
               str = dictionary[2][rand(0, dictionary[2].length)];
                break;
            case 4:
                str = dictionary[3][rand(0, dictionary[3].length)];
                break;
            case 11:
                str = chars[0];
                space = false;
                break;
            case 12:
                str = chars[1];
                space = false;
                break;
            case 13:
                str = chars[2];
                oldSpace = false;
                space = false;
                break;
            case 21:
                str =others[0];
                break;
            case 22:
                str = others[1];
                space = false;
                break;
            case 31:
                str = songName;
                break;
            case 0:
            default:
                space = false;
        }
        if(space) {
            if(oldSpace) {
                if(0 != i) {
                    chorus = chorus+" ";
                }
            } else {
                oldSpace = true;
            }
        }
        if(str) {
            chorus = chorus+str;
        }
    }
    return chorus;
}

// 1 is a verse
// 2 is the chorus
var songPresets = [ [1, 1, 2, 1, 1, 2], [1, 1, 2, 1, 1, 2, 2], [1, 2, 1, 2], [1, 2, 1, 2, 2], [1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2, 2], [1, 1, 2, 1, 2, 1, 2] ];

// generates the whole song
function generate() {
    var song = "";
    var songName =dictionary[0][rand(0, dictionary[0].length)];
    song = song+"<h2>THE "+songName.toUpperCase()+"</h2>";
    var verseLines = [4, 6, 8];
    var numLines = verseLines[rand(0, verseLines.length)];
    var numPreset = rand(0, songPresets.length);
    var chorus = createChorus(songName);
    for (var i = 0; i < songPresets[numPreset].length; i++) {
        switch(songPresets[numPreset][i]) {
            case 1:
               song = song+"<h3>VERSE:</h3>"+createVerse(numLines);
                break;
            case 2:
                song = song+"<h3>CHORUS:</h3>"+chorus;
                break;
            case 0:
            default:
                break;
        }
    }
   return song;
}
</script>
</head>
<body onLoad="document.getElementById('main').innerHTML = generate();">
<h1>POWER METAL LYRICS GENERATOR v0.1</h1>
<h3><i>Генератор ипических текстов</i></h3>
Created by <a href=http://marked-prog.blogspot.com>Marked</a>, 2010
<p><input type="button" value="Generate new lyrics!" onClick="document.getElementById('main').innerHTML = generate();return false;" /></p>
<div id="main"></div>
</body>
</html>
